// 全局自定义指令：
// main.js/main.ts中写

// app.directive(自定义指令名,{
//     mounted(el,binding){}
// })

// 语法： v-auth="{ name: '用户删除' }"
// 作用：复制某个值至剪贴板
// 这个文件中可以声明多个自定义指令
// export 指令名 = 指令配置对象
//direcitves/index.ts
import type { getAuthApi, Children } from '@/types/auth'
import type { Directive, DirectiveBinding } from 'vue'
import { userAsideStore } from '@/stores/aside'

export const auth: Directive = {
  mounted(el: HTMLElement, binding: DirectiveBinding) {
    const { menu } = userAsideStore()
    const temp: Array<string> = []
    menu.forEach((item: getAuthApi) => {
      if (item.children) {
        item.children.forEach((twoItem: Children) => {
          if (twoItem.type === 2) {
            temp.push(twoItem.auth_name)
          }
        })
      }
    })

    console.log(binding.value, temp)

    if (!temp.includes(binding.value.name)) el.remove()
  },
}
